import os
import yaml

# C:\Users\beneo\.config\clash\profiles
user_home_path = os.path.expanduser('~')
wd = os.path.join(user_home_path,'.config','clash','profiles')
os.chdir(wd)
with open('list.yml',encoding='utf8') as yml_file:
    list_yml = yaml.safe_load(yml_file)
for e in list_yml['files']:
    if len(e['url'])>0:
        config_file_path = e['time']
        print(config_file_path)

with open(config_file_path,encoding='utf8') as yml_config_file:
    config_yml = yaml.safe_load(yml_config_file)

def config_entry_append(config_entry_check:str,config_yml_rules:list):
    if not(config_entry_check in config_yml_rules):
        config_yml_rules.insert(0,config_entry_check)


config_entry_check_list = [
    'DOMAIN-KEYWORD,msftconnecttest,DIRECT',
    'DOMAIN-KEYWORD,adobe,REJECT',
    'DOMAIN-KEYWORD,hao123,REJECT',
    'DOMAIN-KEYWORD,ffnews,REJECT',
    'DOMAIN-SUFFIX,flash.cn,REJECT',
    'DOMAIN-SUFFIX,360.cn,REJECT',
    'DOMAIN-SUFFIX,360kuai.com,REJECT',
    'DOMAIN-KEYWORD,izhongcheng,REJECT',
]

for e in config_entry_check_list:
    config_entry_append(e,config_yml['rules'])

print(config_yml)


with open(config_file_path,encoding='utf8',mode='w') as yml_config_writer:
    yaml.dump(config_yml,yml_config_writer)
